#ifndef _SCENE_
#define _SCENE_

#include "BVH.h"

#ifndef L_VERSION
#define L_VERSION   1111225
#endif

#include <llib.h>
using namespace llib;
using namespace llib::geom;

#include <vector>
using namespace std;

class SceneObject {
public:
    enum Type { Solid, Deformable };

    TriMesh     Mesh;
    BVTree      BVH;
    Type        ObjType;
    vector<Boolean> CollisionFlag;

    SceneObject() {}

    /* Initialize the scene object by input vertex and triangle data,
     * the mesh and bvh will be built.
     */
    void    Init(vector<Vec3f>& vertexList, vector<Vec3i>& faceVertexIndexList, Type type);

    /* Initialize the scene object by input triangle mesh,
     * the mesh and bvh will be built.
     */
    void    Init(TriMesh& mesh, Type type);

    /* Fit the BVH hierarchically */
    void    Fit();

    /* Check the collisions between two objects,
     * it will exclude self collision check on default.
     */
    // [2011-12-20] : It's recursive currently.
    void    CollisionCheck(SceneObject& another);

    /* Check the self collision on current object */
    // [2011-12-20] : It's recursive currently.
    void    SelfCollisionCheck();

private:
    /* the tree ref for collision check */
    static SceneObject* _firstObj;
    static SceneObject* _secondObj;

    static void collisionCheck(BVNode* firstNode, BVNode* secondNode);

    static void selfCollisionCheck(BVNode* node);
    static void collisionCheckWithSelf(BVNode* firstNode, BVNode* secondNode);

};













#endif